# python -m cProfile -o rep.prof nps_nogui.py 1000 1000
# runsnake rep.prof

LIBS = libpat_dm_fw_gsl.so libpat_dm_hk.so libpat_dm_jsbsim.so libpat_pprz.so

all: $(LIBS)


###
#
# This is a yet to be written model in C using gsl
#
PYCFLAGS = -shared `pkg-config --libs --cflags python`
GSL_CFLAGS = `pkg-config gsl --cflags`
GSL_LDFLAGS = `pkg-config gsl --libs`

CFLAGS = -Wall -std=gnu99 -I.
LDFLAGS =  -lm

libpat_dm_fw_gsl.so: native/dm_fw_gsl.c
	@echo "\n### Building PAT GSL lib"
	gcc -DPYBINDINGS $(CFLAGS) $(GSL_CFLAGS) $(PYCFLAGS) -o $@ $^ $(LDFLAGS) $(GSL_LDFLAGS)

test_dm_fw_gsl: native/dm_fw_gsl.c
	gcc $(CFLAGS) $(GSL_CFLAGS) -o $@ $^ $(LDFLAGS) $(GSL_LDFLAGS) 


###
#
# Bindings for Hudson/Kahn helicopter dynamic model written in C++
#
HK_ROOT = native/HudsonKahnSim
CPPFLAGS = -Wall
HK_CFLAGS = -I$(HK_ROOT)/src -I$(HK_ROOT)/src/include -I$(HK_ROOT)/src/heli-sim
HK_LDFLAGS = -L$(HK_ROOT)/lib/i386/ -lsim -lmat -lstate
libpat_dm_hk.so: native/dm_hk.cpp
	@echo "\n### Building Hudson/Kahn lib"
	g++ -DPYBINDINGS $(CPPFLAGS) $(HK_CFLAGS) $(PYCFLAGS) -o $@ $^ $(LDFLAGS) $(HK_LDFLAGS)
test_dm_hk: native/dm_hk.cpp
	g++ $(CPPFLAGS) $(HK_CFLAGS) -o $@ $^ $(LDFLAGS) $(HK_LDFLAGS)

clean:
	find . -name '*~' -exec rm {} \;
	find . -name '*.pyc' -exec rm {} \;
	rm -f *.pyc *~ ../config/*~ $(LIBS) test_dm_fw_gsl test_dm_hk

###
#
# Bindings for JSBSim, dynamic model written in C++
#
libpat_dm_jsbsim.so:
	@echo "\n### Building JSBsim lib"
	cd native/JSBSimPython; scons libpat_dm_jsbsim.so
	cp native/JSBSimPython/libpat_dm_jsbsim.so .




###
#
# Flightgear (display) manipulations
#
# http://www.flightgear.org/Docs/FGShortRef.html
#
AIRCRAFT=777-200ER
AIRCRAFT=c172p

start_fg:
#       fgfs --aircraft=$(AIRCRAFT) --timeofday=noon --fdm=null --native-fdm=socket,in,30,,5501,udp&
	fgfs --aircraft=$(AIRCRAFT) --prop:/sim/current-view/view-number=5 --timeofday=noon --fdm=null --native-gui=socket,in,30,,5501,udp&

kill_fg:
	killall fgfs





###
#
# Paparazzi rotorcraft control
#
# see http://paparazzi.enac.fr
#
AC_NAME = BOOZ2
AC_ARCH = sim
PPRZ_DIR=/home/poine/work/python_aero_tlbx/paparazzi_v5.0.0

SRCS= $(PPRZ_DIR)/sw/airborne/math/pprz_trig_int.c                                                      \
      $(PPRZ_DIR)/sw/airborne/math/pprz_geodetic_int.c                                                  \
      $(PPRZ_DIR)/sw/airborne/math/pprz_geodetic_float.c                                                \
      $(PPRZ_DIR)/sw/airborne/math/pprz_geodetic_double.c                                               \
      $(PPRZ_DIR)/sw/airborne/math/pprz_orientation_conversion.c                                        \
      $(PPRZ_DIR)/sw/airborne/state.c                                                                   \
      $(PPRZ_DIR)/sw/airborne/firmwares/rotorcraft/stabilization.c                                      \
      $(PPRZ_DIR)/sw/airborne/firmwares/rotorcraft/stabilization/stabilization_none.c                   \
      $(PPRZ_DIR)/sw/airborne/firmwares/rotorcraft/stabilization/stabilization_rate.c                   \
      $(PPRZ_DIR)/sw/airborne/firmwares/rotorcraft/stabilization/stabilization_attitude_euler_int.c     \
      $(PPRZ_DIR)/sw/airborne/firmwares/rotorcraft/stabilization/stabilization_attitude_ref_euler_int.c \
     ./native/ctl_pprz.c

#      $(PPRZ_DIR)/sw/airborne/firmwares/rotorcraft/stabilization/stabilization_attitude_rc_setpoint.c   \
#      $(PPRZ_DIR)/sw/airborne/firmwares/rotorcraft/autopilot.c                                          \
#      $(PPRZ_DIR)/sw/airborne/subsystems/radio_control.c                                                \


AC_FLAGS = -DSTABILIZATION_ATTITUDE_TYPE_INT                                                     \
           -DSTABILIZATION_ATTITUDE_TYPE_H=\"stabilization/stabilization_attitude_euler_int.h\"  \

#           -DRADIO_CONTROL                                                                       \
#           -DRADIO_CONTROL_TYPE_H=\"subsystems/radio_control/ppm.h\" \

PPRZ_CFLAGS = -Wall -I$(PPRZ_DIR)/sw/include                       \
                    -I$(PPRZ_DIR)/sw/airborne                      \
                    -I$(PPRZ_DIR)/var/$(AC_NAME)                   \
                    -I$(PPRZ_DIR)/sw/airborne/arch/sim/            \
                    -I$(PPRZ_DIR)/sw/airborne/firmwares/rotorcraft \
                    $(AC_FLAGS)

libpat_pprz.so:
	@echo "\n### Building pprz ctl lib"
	gcc $(PPRZ_CFLAGS)  $(SRCS) -o $@ $(LDFLAGS)

